/****************************************************************************
** Copyright (C) 2017 ZhouLiQiu(zhouliqiu@126.com).
**
** This file is part of the qtc_astyle, It is a plugin for Qt Creator.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and associated documentation files (the "Software"), to deal
** in the Software without restriction, including without limitation the rights
** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
** copies of the Software, and to permit persons to whom the Software is
** furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
** THE SOFTWARE.
**
****************************************************************************/
#ifndef VALUE_ACTION_H
#define VALUE_ACTION_H

#include <QAction>
#include <QSettings>

namespace qtc_astyle {
namespace Internal {

class ValueAction : public QAction
{
    Q_OBJECT

public:
    ValueAction(QObject *parent = 0);

    virtual QString strStyle() const;
    Q_SLOT virtual void setStrStyle(QString strStyle);

    virtual QVariant value() const;
    Q_SLOT virtual void setValue(const QVariant &value, bool doemit = true);

    virtual QVariant defaultValue() const;
    Q_SLOT virtual void setDefaultValue(const QVariant &value);

    virtual QString settingsKey() const;
    Q_SLOT virtual void setSettingsKey(const QString &key);
    Q_SLOT virtual void setSettingsKey(const QString &group, const QString &key);

    virtual QString settingsGroup() const;
    Q_SLOT virtual void setSettingsGroup(const QString &group);

    virtual void readSettings(const QSettings *settings);
    Q_SLOT virtual void writeSettings(QSettings *settings);

    virtual void connectWidget(QWidget *widget);
    virtual void disconnectWidget();
    Q_SLOT virtual void apply(QSettings *settings);

    QString toString() const;

signals:
    void valueChanged(const QVariant &newValue);

private:
    Q_SLOT void checkableButtonClicked(bool);
    Q_SLOT void actionTriggered(bool);
    Q_SLOT void spinBoxValueChanged(int);
    Q_SLOT void spinBoxValueChanged(QString);
    Q_SLOT void groupBoxToggled(bool checked);
    Q_SLOT void comboBoxValueChanged(int idx);

    QVariant m_value;
    QVariant m_defaultValue;

    QString m_settingsKey;
    QString m_settingsGroup;

    QString m_strStyle;

    QWidget *m_widget;
};

class ValueActionSet
{
public:
    ValueActionSet() {}
    ~ValueActionSet() {}

    void insert(ValueAction *action, QWidget *widget);
    void apply(QSettings *settings);
    void finish();
    void clear()
    {
        m_list.clear();
    }

    QString searchKeyWords() const;

private:
    QList<ValueAction *> m_list;
};

} // namespace Internal
} // namespace qtc_astyle

#endif // VALUE_ACTION_H
